from django.db import models
from orgs.models import OrgInfo, TeacherInfo


# Create your models here.
class CourseInfo(models.Model):
    image = models.ImageField('课程封面', upload_to='course/', max_length=200)
    name = models.CharField('课程名称', max_length=20)
    study_time = models.IntegerField('学习时长', default=0)
    study_num = models.IntegerField('学习人数', default=0)
    level = models.CharField('课程难度', choices=(('gj', '高级'), ('zj', '中级'), ('cj', '初级')), max_length=5, default='cj')
    love_num = models.IntegerField('收藏数', default=0)
    click_num = models.IntegerField('访问量', default=0)
    desc = models.CharField('课程简介', max_length=200)
    detail = models.TextField('课程详情')
    category = models.CharField('课程类别', choices=(('qd', '前端开发'), ('hd', '后端开发')), max_length=5)
    course_notice = models.CharField('课程公告', max_length=200)
    course_need = models.CharField('课程须知', max_length=100)
    teacher_tell = models.CharField('老师教导', max_length=100)
    is_banner = models.BooleanField('是否轮播', default=False)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    orgInfo = models.ForeignKey(OrgInfo, verbose_name='所属机构', on_delete=models.CASCADE)
    teacherInfo = models.ForeignKey(TeacherInfo, verbose_name='所属讲师', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '课程信息'
        verbose_name_plural = verbose_name


class LessonInfo(models.Model):
    name = models.CharField('章节名称', max_length=50)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    courseInfo = models.ForeignKey(CourseInfo, verbose_name='所属课程', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '章节信息'
        verbose_name_plural = verbose_name


class VideoInfo(models.Model):
    name = models.CharField('视频名称', max_length=50)
    study_time = models.IntegerField('视频时长', default=0)
    url = models.URLField('视频链接', max_length=200, default='http://www.atguigu.com')
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    lessonInfo = models.ForeignKey(LessonInfo, verbose_name='所属章节', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '视频信息'
        verbose_name_plural = verbose_name


class SourceInfo(models.Model):
    name = models.CharField('资源名称', max_length=50)
    down_load = models.FileField('下载路径', upload_to='source/', max_length=200)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    courseInfo = models.ForeignKey(CourseInfo, verbose_name='所属课程', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '资源信息'
        verbose_name_plural = verbose_name
